<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:wh="http://java.sun.com/jsf/composite/wh"
	xmlns:p="http://primefaces.org/ui">
<h:body>
	<ui:composition template="template/template.xhtml">
		<ui:define name="content">
			<h:form id="form" styleClass="horizontal_full">
				<p:panel>
					<p:breadCrumb>
						<p:menuitem value="Categories" url="adminGameManagement.xhtml#" />
						<p:menuitem value="#{adminMBean.selectedGame.name}"
							url="adminGameManagement.xhtml#" />
					</p:breadCrumb>
					<h1>User Management</h1>
					<p>
						Allows you to configure, add and delete users to the game. This users are playing firms in the whole market and make different decisions in order to compete on the market.
						Make sure that the names of the users are unique in the game because they are used for the login. 
					</p>
					<p:dataTable id="userTable" var="user"
						value="#{adminMBean.selectedGame.getUserList()}" selectionMode="single"
						rowKey="#{user.nickname}"
						paginatorTemplate="{RowsPerPageDropdown} {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
						rowsPerPageTemplate="10,25,50,100" paginator="true" rows="100">

						<f:facet name="header">
					            User Overview for Game: #{adminMBean.selectedGame.name}
					        </f:facet>

						<p:column headerText="Name" sortBy="#{user.nickname}">
							<h:outputText value="#{user.nickname}" />
						</p:column>
						
						<p:column headerText="Mail" sortBy="#{user.email}">
							<h:outputText value="#{user.email}" />
						</p:column>
						
						<p:column headerText="Budget" sortBy="#{user.budget}">
							<h:outputText value="#{user.budget}" />
						</p:column>
						
						<p:column headerText="Image" sortBy="#{user.imageValue}">
							<h:outputText value="#{user.imageValue}" />
						</p:column>
						
						<p:column headerText="Configure User">
							<p:commandButton icon="ui-icon-gear" title="Configure" update="userTable"
								action="#{adminMBean.actionGoToUpdateUser()}">
								<f:setPropertyActionListener value="#{user}"
									target="#{adminMBean.selectedUser}" />
							</p:commandButton>
						</p:column>
						
						
						<p:column headerText="Delete User">
							<p:commandButton icon="ui-icon-circle-minus" title="Delete"
								action="#{adminMBean.actionDeleteUser()}" update="userTable">
								<f:setPropertyActionListener value="#{user}" target="#{adminMBean.selectedUser}" />
								<p:confirm header="Confirmation"
												message="Are you sure to delete the user?" icon="ui-icon-alert" />
							</p:commandButton>
							<p:confirmDialog global="true" showEffect="fade"
											hideEffect="explode">
											<p:commandButton value="Yes" type="button"
												styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
											<p:commandButton value="No" type="button"
												styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
							</p:confirmDialog>
						</p:column>
						
						<f:facet name="footer">
							<p:commandButton value="Create New User"
								action="#{adminMBean.actionGoToCreateUser()}"
								update="userTable" icon="ui-icon-circle-plus"/>
						</f:facet>
					</p:dataTable>

				</p:panel>
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>